package com.szss.springbootfirst.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.szss.springbootfirst.entity.R;
import com.szss.springbootfirst.entity.User;
import com.szss.springbootfirst.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author wcx
 * @date 2023/2/6 16:39
 */

@RestController
@CrossOrigin
public class RedisController2 {

    @Autowired
    private IUserService userService;

    @RequestMapping("/queryList")
    public String queryList() throws JsonProcessingException {
        return userService.findDataFormRedis();
    }

    @RequestMapping("/save")
    public void save(User user) throws JsonProcessingException {
//        String simpleUUID = IdUtil.simpleUUID();
//        user.setId(simpleUUID);
        userService.save(user);
    }

    @RequestMapping("/findById")
    public String findById(String id) throws JsonProcessingException {
        return userService.findById(id);
    }

//    @RequestMapping("/findAll")
//    public List<User> findAll(){
//        return userService.findAll();
//    }

    @RequestMapping("/findAll")
    public R findAll(){
        List<User> userList = userService.findAll();
//        Map<String, Object> map = new HashMap<>();
//        map.put("userList",userList);
        return R.ok().data("userList",userList);
    }

    @RequestMapping("/save2")
    public void save2(User user){
        userService.save2(user);
    }
}
